<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>备件选择</title>
    <!-- css代码 start -->
    <link href="../../../../../css/mui.min.css" rel="stylesheet"/>
    <link href="../../../../../css/global.css" rel="stylesheet"/>
    <link href="../../../../../css/style.css" rel="stylesheet"/>
    <style>
        .item_box .item {
            overflow: auto;
        }

        .item_box .item .text {
            height: auto;
            overflow: auto;
        }

        .item_box .item .text span {
            width: 90px;
        }
    </style>
    <!-- css代码 end -->
</head>
<body>
<!-- html代码 start -->
<header class="mui-bar mui-bar-nav">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    <h1 id="title" class="mui-title">备件选择</h1>
</header>
<div class="mui-content">
    <div class="page_cen shadow zp_cen" style="z-index: 1; position: relative;">
        <div class="zp_sear bor_1 autoHeight">
            <button class="btn" id="searchParts"></button>
            <div class="iptBox">
                <input type="text" id="partNo" placeholder="请输入备件号"/>
            </div>
        </div>
        <div class="serarch_btm">
            <input type="text" id="partName" placeholder="请输入备件名称"/>
        </div>
    </div>
    <div class="item_box" id="itemBox">
    </div>
    <div style="height: 20px;"></div>
</div>
<!-- html代码 end -->

<!-- js代码 start -->

<!-- 基础js start -->
<script src="../../../../../js/mui.min.js"></script>
<script src="../../../../../js/utils/h.js"></script>
<script src="../../../../../js/constant.js"></script>
<script src="../../../../../js/common.js"></script>
<script src="../../../../../js/utils/base64.js"></script>
<script src="../../../../../js/utils/md5.js"></script>
<script src="../../../../../js/utils/sortMap.js"></script>
<script src="../../../../../js/utils/http.js"></script>
<script src="../../../../../js/app.js"></script>
<!-- 基础js end -->
<script type="text/javascript" charset="utf-8">
    var wo;
    var serviceNo;
    var phoneHelpId;
    var protType;

    function selectPart(partId, partNo, partName, partSerialNumber, partQty, loanNumber) {
        // var enginnerId = app.getUser().enginnerId;

        // 验证APP端是否存在备件已使用未提交CC的情况
        // app.showWaiting("验证中...")
        // ajaxGet(BASE_URL + 'cc/report/port/selectPartQty', {
        // 	serviceNo: serviceNo,
        // 	helpId: phoneHelpId,
        // 	enginnerId: enginnerId,
        // 	// partSerialNumber: partSerialNumber, //edit by wlf 20200518 报错了 参照服务报告更改此处
        // 	partNumber: partNo
        // }, function(data) {
        // 	app.closeWaiting()
        // 	//console.log(JSON.stringify(data))
        // 	if (data.code === 200) {
        // 		var tmp = data.data
        wo.evalJS('selectPartCallback("' + partId + '", "' + partNo + '", "' + partName + '", "' + partSerialNumber + '", "' +
            (partQty - 0) + '","' + loanNumber + '")');
        mui.back();
        // } else {
        // 	app.toast();
        // }
        // }, function(errorMsg) {
        // 	app.closeWaiting()
        // 	app.toast(errorMsg)
        // });


    }

    (function ($, doc) {
        $.init();

        $.plusReady(function () {
            var self = plus.webview.currentWebview();
            serviceNo = self.serviceNo;
            phoneHelpId = self.phoneHelpId;
            protType = self.type;
            wo = self.opener();

            var selectList = function () {
                var partName = h("#partName").val();
                var partNo = h("#partNo").val();
                var status = 5;
                var enginnerId = app.getUser().enginnerId;

                app.showWaiting()
                ajaxPost(BASE_URL + "cc/spareParts/queryPartByFseIdPostCC", {
                    "Part_name": partName,
                    "Part_no": partNo,
                    "Status": status,
                    "enginner_id": enginnerId,
                    "serviceNo": serviceNo,
                    "helpId": phoneHelpId
                }, function (data) {
                    //alert(JSON.stringify(data))
                    var str = ``;
                    var dataObj = JSON.parse(data.data);
                    var list = dataObj.record;
					var indexArr = [];
                    if (data.code === 200) {
                        listSpareparts(serviceNo, phoneHelpId, protType, function (data) {
                            app.closeWaiting();
                            var hasData = data.data
                            list.forEach(function (item, index) {
                                hasData.forEach(function (v) {
                                    if (v.pid == item.Part_id) {
                                        // list.splice(index, 1)
										indexArr.push(index)
										
                                    }
                                })
                            })
                            for (var i = 0; i < list.length; i++) {
                                var info = list[i];
                                var cn = ''
                                if (info.CustName != null && info.CustName != undefined && info.CustName != 'null') {
                                    cn = info.CustName
                                }
								if(indexArr.indexOf(i) == -1){
									str += `
											<div class="item" onclick="selectPart('${info.Part_id}','${info.Part_no}','${info.Part_name}','${info.service_no}','${info.Part_qty}','${info.Part_DebitNo}')" partId="${info.Part_id}">
												<p class="bar"><span class="number">${info.Part_no}<img src="../../../../../images/icon_204.png" /></span></p>
												<div class="text"><span style="width: 90px;">借货单号：</span><div>${info.Part_DebitNo}</div></div>
												<div class="text"><span style="width: 90px;">客户名称：</span><div>${cn}</div></div>
												<div class="text"><span style="width: 90px;">备件名称：</span><div>${info.Part_name}</div></div>
												<!--<div class="text"><span style="width: 90px;">备件序列号：</span><div>${info.service_no}</div></div>-->
												<div class="text"><span style="width: 90px;">数量：</span><div>${info.Part_qty}</div></div>
												<div class="text"><span style="width: 90px;">partId：</span><div>${info.Part_id}</div></div>
											</div>
										`;
								}
                                
                            }
                            h('#itemBox').html(str);
                        })
                    } else {
						app.closeWaiting();
                        app.toast(data.msg);
                    }
                }, function (errorMsg) {
                    app.closeWaiting();
                    app.toast(errorMsg);
                });
            }

            selectList();

            h('#searchParts').tap(function () {
                selectList();
            })
        });
    }(mui, document));

    function listSpareparts(serviceNo, helpId, type, callback) {
        app.showWaiting()
        ajaxGet(BASE_URL + 'cc/report/port/selectReportPorts', {
            serviceNo,
            helpId,
            type
        }, function (data) {
            callback && callback(data)
        }, function () {
            app.closeWaiting()
            app.toast(errorMsg)
        })
    }

</script>
<!-- js代码 end -->
</body>
</html>
